package com.zues.samples.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonBackReference;

@Entity
@Table(name = "exam_user_subject")
// @ClassId(UserSubject.class)
public class UserSubject implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6157233205695689322L;

	@Id
	@GeneratedValue
	@Column(name = "user_subject_id", length = 11, nullable = false)
	private Integer userSubjectId;

	@Column(name = "user_id", length = 11, nullable = false, insertable = false, updatable = false)
	private String userId;

	@Column(name = "subject_id", length = 11, nullable = false, insertable = false, updatable = false)
	private Integer subjectId;

	@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST })
	@JoinColumn(name = "user_id")
	private User user;

	// @Id
	@ManyToOne(cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST })
	@JoinColumn(name = "subject_id")
	private Subject subject;

	public UserSubject() {
		super();
	}

	

	public UserSubject(User user, Subject subject) {
		super();
		this.user = user;
		this.subject = subject;
	}



	public UserSubject(Integer userSubjectId, String userId, Integer subjectId, User user, Subject subject) {
		super();
		this.userSubjectId = userSubjectId;
		this.userId = userId;
		this.subjectId = subjectId;
		this.user = user;
		this.subject = subject;
	}



	public UserSubject(Integer userSubjectId, User user, Subject subject) {
		super();
		this.userSubjectId = userSubjectId;
		this.user = user;
		this.subject = subject;
	}

	public Integer getUserSubjectId() {
		return userSubjectId;
	}

	public void setUserSubjectId(Integer userSubjectId) {
		this.userSubjectId = userSubjectId;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public Integer getSubjectId() {
		return subjectId;
	}

	public void setSubjectId(Integer subjectId) {
		this.subjectId = subjectId;
	}

	public User getUser() {
		return user;
	}

	@JsonBackReference
	public void setUser(User user) {
		this.user = user;
	}

	public Subject getSubject() {
		return subject;
	}

	@JsonBackReference
	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public String toString() {
		return "UserSubject [user= [ " + ", userName=" + user.getUserName() + ", userAddress=" + user.getAddress()
				+ ", userEmail= " + user.getEmail() + ", subject=" + subject.getName() + "]";
	}

}
